package com.hex.ds.hdrs.period.task.controller;

import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.period.task.dto.MutexPoolDto;
import com.hex.ds.hdrs.period.task.po.MutexPoolGroup;
import com.hex.ds.hdrs.period.task.service.MutexPoolGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "互斥池组管理")
@RequestMapping("/api/mutexPoolGroup")
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class MutexPoolGroupController {

    private final MutexPoolGroupService mutexPoolGroupService;

    @GetMapping("/selectPages")
    @ApiOperation("查询互斥池组管理配置")
    public ResponseEntity<Object> selectPages(MutexPoolGroup mutexPoolGroup, Page page) {
        log.debug("进入了MutexPoolGroupController的selectPages方法");
        return new ResponseEntity(mutexPoolGroupService.queryListByPage(mutexPoolGroup, page), HttpStatus.OK);
    }

    @PostMapping("add")
    @ApiOperation("添加互斥池组")
    public ResponseEntity<Object> add(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("【AppGroupConfController.add】：{}", mutexPoolDto.toString());
        return new ResponseEntity(mutexPoolGroupService.add(mutexPoolDto), HttpStatus.OK);
    }

    @PutMapping("edit")
    @ApiOperation("修改互斥池组")
    public ResponseEntity<Object> modifyById(@RequestBody MutexPoolDto mutexPoolDto) {
        log.info("【AppGroupConfController.modifyById】：{}", mutexPoolDto.toString());
        mutexPoolGroupService.modifyById(mutexPoolDto);
        return new ResponseEntity(HttpStatus.OK);
    }

    @DeleteMapping("/del")
    @ApiOperation("删除互斥池信息/批量")
    public ResponseEntity<Object> batcheRemove(@RequestBody List<String> groupCodes) {
        log.debug("删除互斥池信息【MutexPoolGroupController.del】========》{}", groupCodes);
        mutexPoolGroupService.batcheRemove(groupCodes);
        return new ResponseEntity<>("删除成功！", HttpStatus.OK);
    }

    @PostMapping("/checkAppData")
    @ApiOperation("判断是否重复")
    public ResponseEntity<Object> checkGroupCode(@RequestBody MutexPoolGroup mutexPoolGroup) {
        log.info("【AppGroupConfController的checkAppData】：{}", mutexPoolGroup.toString());
        boolean result = mutexPoolGroupService.checkGroupCode(mutexPoolGroup);
        return new ResponseEntity(result, HttpStatus.OK);
    }
}
